﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DAL;
using System.Data;
using System.Data.SqlClient;

namespace BLL
{
    public class TINHTRANGTKBLL
    {
        DataService DB = new DataService();

        //get all values
        public List<TINHTRANGTK> getALL()
        {
            string sql = "select * from tinhtrangtk";
            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);

            List<TINHTRANGTK> lstTttk = new List<TINHTRANGTK>();
            foreach (DataRow r in table.Rows)
            {
                TINHTRANGTK tttk = new TINHTRANGTK();
                tttk.matinhtrangtk = (int)r[0];
                tttk.tentinhtrangtk = (string)r[1];
                lstTttk.Add(tttk);
            }
            return lstTttk;
        }

        //insert value
        public void insert(string tentinhtrangtk)
        {

            string sql = "insert into tinhtrangtk values (@tentinhtrangtk)";
            SqlParameter paraTen = new SqlParameter("tentinhtrangtk", tentinhtrangtk);
            DB.ExecuteNonQuery(sql,paraTen);

        }

        public void update(int idTinhtrang, string tenTinhtrang)
        {

            string sql = "update tinhtrangtk set tentinhtrangtk = '" + tenTinhtrang + "' where matinhtrangtk = " + idTinhtrang.ToString();
            DB.ExecuteNonQuery(sql);
        }

        public void delete(int idTinhtrang)
        {
            string sql = "delete from tinhtrangtk where matinhtrangtk = " + idTinhtrang.ToString();
            DB.ExecuteNonQuery(sql);
        }

        //get count
        public int count()
        {
            string sql = "select count(*) from tinhtrangtk";
            return Int32.Parse(DB.ExecuteScalar(sql));
        }

        public DataTable getallTinhtrangtk()
        {
            string sql = "select * from tinhtrangtk";
            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            return table;
        }

        public int Using()
        {
            string sql = "select * from tinhtrangtk where tentinhtrangtk = 'using'";

            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            DataRow r = table.Rows[0];

            return (int)r[0];
        }

        public int Block()
        {
            string sql = "select * from tinhtrangtk where tentinhtrangtk = 'block'";

            DataTable table = new DataTable();
            table = DB.ExecuteReader(sql);
            DataRow r = table.Rows[0];

            return (int)r[0];
        }
    }
}
